﻿Adjustment = {
    AdjustmentUpdatePopUpId: '',
    CurrentRow: null,
    OnAddAdjustmentClick: function () {
        $('#btnAddAdjustment').live("click", function (e) {
            e.preventDefault();
            Adjustment.AdjustmentUpdatePopUpId = $(this).attr("id");
            PopUpDialog.UrlDialog("Adjustment", 420, 420, true, "../PopupBoxes/AdjustmentDialogBox.aspx?id=0", $(this).attr("id"));
        });
    },
    OnUpdateAdjustmentClick: function () {
        $('table#Adjustmenttbl .btnUdpate').live("click", function (e) {
            e.preventDefault();
            var id = $(this).attr("data-id");
            Adjustment.CurrentRow = $(this).closest("tr");
            Adjustment.AdjustmentUpdatePopUpId = id;

            PopUpDialog.UrlDialog("Adjustment", 420, 420, true, "../PopupBoxes/AdjustmentDialogBox.aspx?id=" + id, id);
        });
    },
    OnDeleteAdjustmentClick: function () {
        $('table#Adjustmenttbl .btnDelete').live("click", function (e) {
            e.preventDefault();
            if (confirm('Are you sure you want to delete item?')) {
                var id = $(this).attr("data-id");
                var json = JSON.stringify({ Id: id });
                Adjustment.CurrentRow = $(this).closest("tr");
                $.ajax({
                    type: "POST",
                    url: "../Webservices/EmployeeWebService.asmx/DeleteAdjustment",
                    data: json,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        var response = eval('(' + data.d + ')');
                        if (response.Success) {
                            Adjustment.CurrentRow.remove();
                        }
                    }
                });

            }
        });
    },
    SetRowData: function (Obj) {
        if (Obj.IsAdded) {
            location.reload(true);
        }
        var id = Obj.AdjustmentItem.Id;
        var code = Obj.AdjustmentItem.Code;
        var description = Obj.AdjustmentItem.Description;
        var accountType = Obj.AdjustmentItem.strAccountType;
        var accountSign = Obj.AdjustmentItem.strAccountSign;


        Adjustment.CurrentRow.find("td").eq(0).html(id);
        Adjustment.CurrentRow.find("td").eq(1).html(code);
        Adjustment.CurrentRow.find("td").eq(2).html(description);
        Adjustment.CurrentRow.find("td").eq(3).html(accountType);
        Adjustment.CurrentRow.find("td").eq(4).html(accountSign);

    }
}

$(document).ready(function () {
    Adjustment.OnAddAdjustmentClick();
    Adjustment.OnUpdateAdjustmentClick();
    Adjustment.OnDeleteAdjustmentClick();
});